<?php
declare(strict_types=1);

namespace App\Http\Controllers\User;

use App\Exceptions\DbException;
use App\Http\Controllers\Controller;
use App\Http\Requests\Image\AuthorPublishWallPaperValidate;
use App\Http\Requests\User\AuthorIdentValidate;
use App\Library\Response;
use App\Logic\User\Service\User\AuthorService;
use Illuminate\Http\JsonResponse;

class AuthorController extends Controller
{
    public function audit(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceAuditState());
    }

    /**
     * 创作者发布壁纸
     * @param AuthorPublishWallPaperValidate $validate
     * @return JsonResponse
     */
    public function publishWallPaper(AuthorPublishWallPaperValidate $validate): JsonResponse
    {
        $publishResult = (new AuthorService())->servicePublish(request()->all());
        if ($publishResult["code"] == 0) {
            return Response::success($publishResult);
        }
        return Response::error($publishResult);
    }

    public function info(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceFind(request()->all()));
    }

    public function update(AuthorIdentValidate $validate): JsonResponse
    {
        $update = (new AuthorService())->serviceUpdate(request()->all());
        if ($update["code"] == 4) {
            return Response::success($update);
        }
        return Response::error($update);
    }

    public function getInfo(): JsonResponse
    {
        return Response::success((new AuthorService())->getAuthorInfo(request()->all()));
    }

    public function totalData(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceTotalData());
    }

    public function currentWeek(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceCurrentWeek());
    }

    /**
     * @return JsonResponse
     * @throws DbException
     */
    public function fansList(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceFansList(request()->all()));
    }

    /**
     * @return JsonResponse
     * @throws DbException
     */
    public function collectionList(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceCollection(request()->all()));
    }

    /**
     * @return JsonResponse
     * @throws DbException
     */
    public function shareList(): JsonResponse
    {
        return Response::success((new AuthorService())->serviceShare(request()->all()));
    }
}
